package demo.terrain;

import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;

import org.lwjgl.util.glu.Sphere;

import engine.gameObject.GameObject;
import engine.gameObject.camera.FlyoverCamera;
import engine.gameObject.terrain.Terrain;
import engine.gameObject.terrain.TerrainLoader;
import engine.light.EnvironmentLight;
import engine.loader.texture.TextureLoader;
import engine.scene.Scene;

public class SimpleTerrainScene extends Scene {

	public SimpleTerrainScene() {
		super("terrain");
	}

	@Override
	public void init() {
		setCurrentCamera(new FlyoverCamera());
		getCurrentCamera().setNearPane(100);
		getCurrentCamera().setFarPane(300);
		Terrain terrain = TerrainLoader.loadRAW("test/testMap", 128, 0.1f, 32);
		terrain.setInNearPane(false);
		addGameObject(terrain);

		// a sky object
		GameObject s2 = new GameObject() {
			int tex = TextureLoader.loadTexture("test/sky.png");
			Sphere s = new Sphere();

			@Override
			public void render(float timeElapsed) {
				glColor4f(1, 1, 1, 1);
				s.setTextureFlag(true);
				glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D, tex);

				s.draw(11, 10, 10);

				glDisable(GL_TEXTURE_2D);
			}
		};
		setSkyObject(s2);

		EnvironmentLight light = new EnvironmentLight();
		light.setAmbient(0.3f, 0.3f, 0.3f);
		light.setDirection(-1, 1, -1);
		light.setDiffuse(0.5f, 0.5f, 0.5f);
		addLight(light);
	}
}
